import useHttp from '@/api/useHttp';
import {BasicResp} from "@/api/types";
export interface RegParams{
    username:string;
    password:string;
    email:string;
}
export const reqUserRegister = (params:RegParams) =>{
    return useHttp<BasicResp<null>>({
        url:`/v1/user`,
        method: 'post',
    })
}
export interface LoginParams {
    username: string;
    password: string;
}
export interface LoginResult {
    info: LoginInfo;
    token: string;
}

export interface LoginInfo {
    id: number;
    create_time: string;
    update_time: string;
    username: string;
    email: string;
    role: string;
}
export const reqUserLogin=(params:LoginParams)=>{
    return useHttp<BasicResp<LoginResult>>({
        url:`/api/v1/user/login`,
        method:'post',
        data:{...params}
    });
}
export interface UserListData{
    list:LoginInfo[];
    total:number;
}

export const reqUserList=(page:number,size:number)=>{
    return useHttp<BasicResp<UserListData>>({
       url:`/api/admin/v1/user`,
       method:'get',
       params:{page,size},
    });
}

export const reqUserAdd=(params:RegParams)=>{
    return useHttp<BasicResp<null>>({
        url:`/api/v1/user`,
        method:'post',
        data:{...params},
    });
}

export const reqUserDel = (id:number)=>{
    return useHttp<BasicResp<null>>({
       url:`/api/admin/v1/user/${id}`,
       method:`delete`,
    });
}